import Mock from 'mockjs'

const List = []
const count = 100
const stationNames = ['站A', '站B', '站C']
const directions = ['UP_DIRECTION', 'DOWN_DIRECTION', 'UNKOWN_DIRECTION']

for (let i = 0; i < count; i++) {
  List.push(
    Mock.mock({
      id: i,
      stationName: stationNames[i%3],   // 站名
      trainNo: "机车" + i%9,    // 机车号
      curSpeed: 11,        // 速度
      curTsr: 11,          // 限速
      workItem: "A00" + i%5,    // 作业单号
      hungIndex: 1,        // 执行钩序
      signalName: "D11",   // 信号机名称
      signalState: "开放", // 信号机状态
      signalDistance: 100, // 距离
      section: "IIG",      // 前方区段
      trainNum: 1,         // 挂车数量
      direction: directions[i%3],  // 上行"UP_DIRECTION"、下行"DOWN_DIRECTION"、未知"UNKOWN_DIRECTION"
      time: Mock.Random.datetime('yyyy-MM-dd HH:mm:ss'), // "2024-03-15 09:52:12",
      pdsignal: "推进",    // 平调信号
      cworkItem: "场1"     // 场号
    })
  )
}

export default [
  // 数据查询-机车信息-获取所有车站名称信息
  {
    url: '/station/getNames',
    type: 'get',
    response: _ => {
      return {
        code: 0,
        msg: "",
        data: [
          "站B", "站C", "站D"
        ]
      }
    }
  },

  // 数据查询-机车信息
  {
    url: '/train',
    type: 'get',
    response: config => {
      const { station, trainNo, startTime, endTime, workNo } = config.query
      let mockList = List.filter(item => {
        if (startTime && new Date(startTime).getTime() > new Date(item.time).getTime()) return false
        if (endTime && new Date(endTime).getTime() < new Date(item.time).getTime()) return false
        if (station && station !== item.stationName) return false
        if (workNo && workNo !== item.workItem) return false
        if (trainNo && trainNo !== item.trainNo) return false
        return true
      })

      //const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

      return {
        code: 0,
        msg: "",
        data: mockList
      }
    }
  }
]
